Ext.define('SA.view.survey.Editor', {
	extend: 'Ext.form.Panel',
	alias: 'widget.surveyeditor',
	
	listeners: {
		'afterrender': function() {
			console.log('Editor is rendered');
		}
	},
	

	
	initComponent: function() {
		Ext.apply(this, {
			title: 'Survey Details',
			items: [{
				xtype: 'textfield',
				fieldLabel: 'Name',
				name: 'name',
				allowBlank: false
			}, {
				xtype: 'combobox',
				fieldLabel: 'Category',
				name: 'categoryId',
				queryMode: 'local',
				store: this.createCategoryStore(),
				valueField: 'id',
				displayField: 'name'
			}, {
				xtype: 'combobox',
				fieldLabel: 'Voice Recording',
				name: 'voiceRecording',
				queryMode: 'local',
				store: this.createVoiceRecordingStore(),
				valueField: 'id',
				displayField: 'name'
			}, {
				xtype: 'combobox',
				fieldLabel: 'Result Followup',
				name: 'resultFollowup',
				queryMode: 'local',
				store: this.createFollowupStore(),
				valueField: 'value',
				displayField: 'name'
			}, {
				xtype: 'combobox',
				fieldLabel: 'Display Result Average',
				name: 'displayResultAverage',
				queryMode: 'local',
				store: this.creatResultAverageStore(),
				valueField: 'value',
				displayField: 'name'
			},{
				xtype: 'combobox',
				fieldLabel: 'Status',
				name: 'status',
				queryMode: 'local',
				store: 'SurveyStatuses',
				valueField: '_name',
				displayField: '_name'
			}, {
				// TODO Make this appear only when a Inbound/Outbound types
				xtype: 'textfield',
				fieldLabel: 'VXML',
				name: 'vxml'
			}],
			buttons: [{
    	    	text: 'Save',
    	    	action: 'save'
    	    	
    	    }, { 
    	    	text: 'Cancel',
    	    	action: 'cancel'
    	    }]
		});
		this.callParent(arguments);
		
	},
	
	createCategoryStore: function() {
		return Ext.create('Ext.data.Store', {
		    fields: [
		    	{name: 'id', type: 'int'},
		    	'name', 
		    	{name: 'productId', type: 'init'},
		    ],
		    data : [
		        {'id':1, 'name':'Web Survey', 'productId': 3},
		        {'id':2, 'name':'Survey - Technician', 'productId': 3},
		        {'id':5, 'name':'Survey - Counter', 'productId': 3}
		    ]
		});
	
	},
	
	createVoiceRecordingStore: function() {
		return Ext.create('Ext.data.Store', {
		    fields: ['id', 'name'],
		    data : [
		        {'id':0, 'name':'No'},
		        {'id':1, 'name':'Yes'}
		    ]
		});
	
	},
	
	createFollowupStore: function() {
		return Ext.create('Ext.data.Store', {
		    fields: [{name: 'value', type: 'boolean' },
	             'name'],
		    data : [
		        {'value': false, 'name':'No'},
		        {'value': true, 'name':'Yes'}
		    ]
		});
	
	},
	
	creatResultAverageStore: function() {
		return Ext.create('Ext.data.Store', {
		    fields: [{name: 'value', type: 'boolean' },
		             'name'],
		    data : [
		        {'value': false, 'name':'No'},
		        {'value': true, 'name':'Yes'}
		    ]
		});
	
	}
	
});